import cloneDeep from 'lodash/cloneDeep';
import AllControlProperty from '@/model/designer/allControlProperty';
import {
  TextOptions,
  DataFormatTimeOptions,
  DataFormatNumberOptions,
  MobileShowModeOptions,
  DefaultItemListOptions,
  FileMaxSizeOptions,
  MapRangeOptions,
  MobileShowModeSubGridOptions,
  ControlSizeOptions,
  UserReadScopeOptions,
  SchemaIconOptions,
  DisplaySettingOptions,
  LayoutPercentOptions,
  AlignTypeOptions,
  ActionOrderOptions,
  TurnRuleOptions,
  HandlerEmptyOptions,
  MessageNoticeOptions,
  HandlerTimeOptions,
  CommitTypeOptions,
  SignOptions,
} from '@/model/objectMap/controlMap';
import { GetButton } from '@/views/flowDesign/handle';

// 基础卡片
export const FormTextBoxProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '单行文本',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  ctlValue: {
    defaultValue: '',
  },
  dataFormat: {
    defaultValue: 'text',
    propData: {
      options: TextOptions,
    },
  },
  // repeatFormat: {
  //   defaultValue: false,
  // },
  placeHolder: {
    defaultValue: '请输入',
  },
  description: {
    defaultValue: '',
  },
};
export const FormTextAreaProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '多行文本',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  ctlValue: {
    defaultValue: '',
  },
  rows: {
    defaultValue: 3,
  },
  placeHolder: {
    defaultValue: '请输入',
  },
  description: {
    defaultValue: '',
  },
};
export const FormDatetimeProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '日期',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  ctlValue: {
    defaultValue: '',
    uiType: 'DatetimeControl',
  },
  dataFormat: {
    defaultValue: 'YYYY-MM-DD',
    propData: {
      options: DataFormatTimeOptions,
    },
  },
  description: {
    defaultValue: '',
  },
};
export const FormNumberProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '数字',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  ctlValue: {
    defaultValue: undefined,
    uiType: 'InputNumberControl',
  },
  dataFormat: {
    defaultValue: {
      type: 'data',
      decimals: 0,
      isShowDecimal: false,
      isShowThousand: false,
    },
    propData: {
      options: DataFormatNumberOptions,
    },
    uiType: 'FormatNumberControl',
  },
  description: {
    defaultValue: '',
  },
};
export const FormRadioProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '单选框',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  mobileShowMode: {
    defaultValue: 'slide',
    propData: {
      options: MobileShowModeOptions,
    },
  },
  ctlValue: {
    defaultValue: '',
  },
  defaultItem: {
    defaultValue: DefaultItemListOptions,
    uiType: 'TiledListControl',
  },
  description: {
    defaultValue: '',
  },
};
export const FormCheckboxProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '复选框',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  mobileShowMode: {
    defaultValue: 'slide',
    propData: {
      options: MobileShowModeOptions,
    },
  },
  ctlValue: {
    defaultValue: [],
    uiType: 'MultiSelectControl',
  },
  defaultItem: {
    defaultValue: DefaultItemListOptions,
    uiType: 'TiledListControl',
  },
  description: {
    defaultValue: '',
  },
};
export const FormSelectProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '下拉框',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  mobileShowMode: {
    defaultValue: 'slide',
    propData: {
      options: MobileShowModeOptions,
    },
  },
  ctlValue: {
    defaultValue: '',
  },
  defaultItem: {
    defaultValue: DefaultItemListOptions,
    uiType: 'TiledListControl',
  },
  description: {
    defaultValue: '',
  },
};
export const FormSwitchProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '是/否',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  ctlValue: {
    defaultValue: false,
  },
  description: {
    defaultValue: '',
  },
};
export const FormAttachmentProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '附件',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  fileMaxSize: {
    defaultValue: '10',
    propData: {
      options: FileMaxSizeOptions,
    },
  },
  description: {
    defaultValue: '',
  },
};
export const FormImageProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '图片',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  dataFormat: {
    defaultValue: {
      multi: true,
      scanJust: false,
    },
    uiType: 'FormatImageControl',
  },
  description: {
    defaultValue: '',
  },
};
export const FormAddressProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '地址',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  dataFormat: {
    defaultValue: {
      address: 'provinceCityCounty',
      isShowDetail: true,
    },
  },
  ctlValue: {
    defaultValue: '',
    uiType: 'AddressControl',
  },
  description: {
    defaultValue: '',
  },
};
export const FormMapProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '位置',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  mapRange: {
    defaultValue: 'nearby',
    propData: {
      options: MapRangeOptions,
    },
  },
  description: {
    defaultValue: '',
  },
};
export const FormUserProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '人员单选',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  ctlValue: {
    defaultValue: '',
  },
  unitSelectionRange: {
    defaultValue: '',
  },
  isAllowRead: {
    defaultValue: true,
  },
  description: {
    defaultValue: '',
  },
};
export const FormMultiUserProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '人员多选',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  ctlValue: {
    defaultValue: '',
  },
  unitSelectionRange: {
    defaultValue: '',
  },
  isAllowRead: {
    defaultValue: true,
  },
  description: {
    defaultValue: '',
  },
};
export const FormDepartmentProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '部门单选',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  ctlValue: {
    defaultValue: '',
  },
  unitSelectionRange: {
    defaultValue: '',
  },
  isAllowRead: {
    defaultValue: true,
  },
  description: {
    defaultValue: '',
  },
};
export const FormMultiDepartmentProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '部门多选',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  ctlValue: {
    defaultValue: '',
  },
  unitSelectionRange: {
    defaultValue: '',
  },
  isAllowRead: {
    defaultValue: true,
  },
  description: {
    defaultValue: '',
  },
};
// 布局卡片
export const FormGroupTitleProps = {
  displayName: {
    defaultValue: '分组标题',
  },
  alignType: {
    defaultValue: 'left',
    propData: {
      options: AlignTypeOptions,
    },
  },
};
export const FormLayoutProps = {
  layoutType: {
    defaultValue: 'twoCols', // 通过layoutPercent取值
    propData: {
      options: LayoutPercentOptions,
    },
  },
  layoutPercent: {
    defaultValue: 'twoCols1',
    propData: {
      options: LayoutPercentOptions,
    },
  },
};
export const FormDescriptionProps = {
  ctlValue: {
    defaultValue: '描述',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
};
export const FormSubGridProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '子表',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  mobileShowMode: {
    defaultValue: 'column',
    propData: {
      options: MobileShowModeSubGridOptions,
    },
  },
};
export const FormTabProps = {
  tabTitile: {
    defaultValue: [
      {
        key: '1',
        name: '标签页1',
      },
      {
        key: '2',
        name: '标签页2',
      },
      {
        key: '3',
        name: '标签页3',
      },
    ],
  },
};
// 系统卡片
export const FormSeqNoProps = {
  cardCode: {
    defaultValue: 'SeqNo',
  },
  displayName: {
    defaultValue: '流水号',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  description: {
    defaultValue: '',
  },
};
export const FormCreaterProps = {
  cardCode: {
    defaultValue: 'Creater',
  },
  displayName: {
    defaultValue: '创建人',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  description: {
    defaultValue: '',
  },
};
export const FormOwnerProps = {
  cardCode: {
    defaultValue: 'Owner',
  },
  displayName: {
    defaultValue: '拥有者',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  unitSelectionRange: {
    defaultValue: '',
  },
  description: {
    defaultValue: '',
  },
};
export const FormOwnerDeptProps = {
  cardCode: {
    defaultValue: 'OwnerDept',
  },
  displayName: {
    defaultValue: '所属部门',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  unitSelectionRange: {
    defaultValue: '',
  },
  description: {
    defaultValue: '',
  },
};
export const FormCreateTimeProps = {
  cardCode: {
    defaultValue: 'CreateTime',
  },
  displayName: {
    defaultValue: '创建时间',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  description: {
    defaultValue: '',
  },
};
export const FormUpdateTimeProps = {
  cardCode: {
    defaultValue: 'UpdateTime',
  },
  displayName: {
    defaultValue: '修改时间',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  description: {
    defaultValue: '',
  },
};
// 高级卡片
export const FormQueryProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '关联表单',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  associateFormCode: {
    defaultValue: '',
  },
  dataFilter: {
    defaultValue: '',
  },
  dataFillRule: {
    defaultValue: '',
  },
  associateField: {
    defaultValue: '',
  },
  description: {
    defaultValue: '',
  },
};
export const FormMultiQueryProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '关联表单多选',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  associateFormCode: {
    defaultValue: '',
  },
  dataFilter: {
    defaultValue: '',
  },
  associateField: {
    defaultValue: '',
  },
  description: {
    defaultValue: '',
  },
};
export const FormAssociatePropertyProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '关联属性',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  associateFormCode: {
    defaultValue: '',
  },
  associateField: {
    defaultValue: '',
  },
  description: {
    defaultValue: '',
  },
};
export const FormFormulaProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '公式型卡片',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  dataFormat: {
    defaultValue: '',
    uiType: 'SwitchListControl',
  },
  calcFormulaRule: {
    defaultValue: '',
  },
  calcFormulaType: {
    defaultValue: 'num',
  },
  description: {
    defaultValue: '',
  },
};
export const FormButtonProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '按钮',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  buttonExtend: {
    defaultValue: '',
  },
};
export const FormHandSignProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '手写签名',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  dataFormat: {
    defaultValue: '',
    uiType: 'SwitchListControl',
  },
  description: {
    defaultValue: '',
  },
};
export const FormOcrProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '文字识别',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  controlSize: {
    defaultValue: '100%',
    propData: {
      options: ControlSizeOptions,
    },
  },
  serviceInfo: {
    defaultValue: '',
  },
  dataFillRule: {
    defaultValue: '',
  },
  dataFillConfig: {
    defaultValue: '',
  },
  description: {
    defaultValue: '',
  },
};
export const FormEsignProps = {
  cardCode: {
    defaultValue: '',
  },
  displayName: {
    defaultValue: '电子签章',
  },
  // displayRule: {
  //   defaultValue: '',
  // },
  startEsignConfig: {
    defaultValue: '',
  },
  syncEsignConfig: {
    defaultValue: '',
  },
  description: {
    defaultValue: '',
  },
};
// 表单属性
export const FormPropertyProps = {
  schemaCode: {
    defaultValue: '',
  },
  schemaName: {
    defaultValue: '未命名表单',
  },
  // formGroup: {
  //   defaultValue: '',
  // },
  schemaIcon: {
    defaultValue: 'icon-luoshu-form1',
    propData: {
      options: SchemaIconOptions,
    },
  },
  dataTitle: {
    defaultValue: [],
    propData: {
      maxTagCount: 10,
    },
  },
  userReadScope: {
    defaultValue: 'role',
    propData: {
      options: UserReadScopeOptions,
    },
  },
  isShowComment: {
    defaultValue: false,
    propData: {
      disabled: true,
    },
  },
  isShowTaskNotice: {
    defaultValue: false,
    propData: {
      disabled: true,
    },
  },
  isShowActionLog: {
    defaultValue: false,
    propData: {
      disabled: true,
    },
  },
  displaySetting: {
    defaultValue: {
      pc: true,
      mobile: true,
    },
    propData: {
      options: DisplaySettingOptions,
    },
  },
};
// 节点属性
export const TransactorNodePropertyProps = {
  nodeId: {
    defaultValue: '',
  },
  nodeName: {
    defaultValue: '',
  },
  actionHandler: {
    name: '经办人',
    defaultValue: [],
  },
  actionAuth: {
    defaultValue: [],
  },
  actionBtn: {
    defaultValue: GetButton('transactor'),
  },
  actionOrder: {
    defaultValue: 'same',
    propData: {
      options: ActionOrderOptions,
    },
  },
  // turnRule: {
  //   defaultValue: {
  //     type: 'count',
  //     data: 1,
  //   },
  //   propData: {
  //     options: TurnRuleOptions,
  //   },
  // },
  handlerEmpty: {
    defaultValue: 'admin',
    propData: {
      options: HandlerEmptyOptions,
    },
  },
  messageNotice: {
    defaultValue: {
      isImmediate: true,
      type: 'system',
    },
    propData: {
      options: MessageNoticeOptions,
    },
  },
  handlerTime: {
    defaultValue: {
      type: 'all',
      data: 8,
      commitType: 'autoCommit',
    },
    propData: {
      options: HandlerTimeOptions,
      commitTypeOptions: CommitTypeOptions,
    },
  },
};
export const ApproveNodePropertyProps = {
  nodeId: {
    defaultValue: '',
  },
  nodeName: {
    defaultValue: '',
  },
  actionHandler: {
    name: '审批人',
    defaultValue: [],
  },
  actionAuth: {
    defaultValue: [],
  },
  actionBtn: {
    defaultValue: GetButton('approve'),
  },
  actionOrder: {
    defaultValue: 'same',
    propData: {
      options: ActionOrderOptions,
    },
  },
  // turnRule: {
  //   defaultValue: {
  //     type: 'count',
  //     data: 1,
  //   },
  //   propData: {
  //     options: TurnRuleOptions,
  //   },
  // },
  handlerEmpty: {
    defaultValue: 'admin',
    propData: {
      options: HandlerEmptyOptions,
    },
  },
  messageNotice: {
    defaultValue: {
      isImmediate: true,
      type: 'system',
    },
    propData: {
      options: MessageNoticeOptions,
    },
  },
  handlerTime: {
    defaultValue: {
      type: 'all',
      data: 8,
      commitType: 'autoCommit',
    },
    propData: {
      options: HandlerTimeOptions,
      commitTypeOptions: CommitTypeOptions,
    },
  },
};
export const CopyNodePropertyProps = {
  nodeId: {
    defaultValue: '',
  },
  nodeName: {
    defaultValue: '抄送节点',
  },
  actionHandler: {
    name: '抄送人',
    defaultValue: [],
  },
  actionAuth: {
    defaultValue: [],
  },
  messageNotice: {
    defaultValue: {
      isImmediate: true,
      type: 'system',
    },
    propData: {
      options: MessageNoticeOptions,
    },
  },
};
export const StartNodePropertyProps = {
  nodeId: {
    defaultValue: '',
  },
  nodeName: {
    defaultValue: '开始',
  },
};
export const EndNodePropertyProps = {
  nodeId: {
    defaultValue: '',
  },
  nodeName: {
    defaultValue: '结束',
  },
  messageNotice: {
    defaultValue: {
      isImmediate: true,
      type: 'system',
    },
    propData: {
      options: MessageNoticeOptions,
    },
  },
};
// 流程属性
export const FlowPropertyProps = {
  sign: {
    defaultValue: {
      report: false,
      upload: false,
    },
    propData: {
      options: SignOptions,
    },
  },
};

const GetGroupControl = (group: { [key: string]: any }) => {
  const groupProperty = {};
  Object.keys(group).forEach((key: any) => {
    const obj = cloneDeep(AllControlProperty[key]);
    Object.assign(obj, group[key]);
    Object.assign(groupProperty, {
      [key]: obj,
    });
  });
  return groupProperty;
};

export const FormTextBox = GetGroupControl(FormTextBoxProps);
export const FormTextArea = GetGroupControl(FormTextAreaProps);
export const FormDatetime = GetGroupControl(FormDatetimeProps);
export const FormNumber = GetGroupControl(FormNumberProps);
export const FormRadio = GetGroupControl(FormRadioProps);
export const FormCheckbox = GetGroupControl(FormCheckboxProps);
export const FormSelect = GetGroupControl(FormSelectProps);
export const FormSwitch = GetGroupControl(FormSwitchProps);
export const FormAttachment = GetGroupControl(FormAttachmentProps);
export const FormImage = GetGroupControl(FormImageProps);
export const FormAddress = GetGroupControl(FormAddressProps);
export const FormMap = GetGroupControl(FormMapProps);
export const FormUser = GetGroupControl(FormUserProps);
export const FormMultiUser = GetGroupControl(FormMultiUserProps);
export const FormDepartment = GetGroupControl(FormDepartmentProps);
export const FormMultiDepartment = GetGroupControl(FormMultiDepartmentProps);

export const FormGroupTitle = GetGroupControl(FormGroupTitleProps);
export const FormLayout = GetGroupControl(FormLayoutProps);
export const FormDescription = GetGroupControl(FormDescriptionProps);
export const FormSubGrid = GetGroupControl(FormSubGridProps);
export const FormTab = GetGroupControl(FormTabProps);

export const FormSeqNo = GetGroupControl(FormSeqNoProps);
export const FormCreater = GetGroupControl(FormCreaterProps);
export const FormOwner = GetGroupControl(FormOwnerProps);
export const FormOwnerDept = GetGroupControl(FormOwnerDeptProps);
export const FormCreateTime = GetGroupControl(FormCreateTimeProps);
export const FormUpdateTime = GetGroupControl(FormUpdateTimeProps);

export const FormQuery = GetGroupControl(FormQueryProps);
export const FormMultiQuery = GetGroupControl(FormMultiQueryProps);
export const FormAssociateProperty = GetGroupControl(
  FormAssociatePropertyProps,
);
export const FormFormula = GetGroupControl(FormFormulaProps);
export const FormButton = GetGroupControl(FormButtonProps);
export const FormHandSign = GetGroupControl(FormHandSignProps);
export const FormOcr = GetGroupControl(FormOcrProps);
export const FormEsign = GetGroupControl(FormEsignProps);

export const FormProperty = GetGroupControl(FormPropertyProps);

export const TransactorNodeProperty = GetGroupControl(
  TransactorNodePropertyProps,
);
export const ApproveNodeProperty = GetGroupControl(ApproveNodePropertyProps);
export const CopyNodeProperty = GetGroupControl(CopyNodePropertyProps);
export const StartNodeProperty = GetGroupControl(StartNodePropertyProps);
export const EndNodeProperty = GetGroupControl(EndNodePropertyProps);
export const FlowProperty = GetGroupControl(FlowPropertyProps);
